//
//  SDHSportsHomeNewsCell.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/7.
//

#import "SDHSportsHomeNewsCell.h"
#import "UIImageView+YQAdd.h"
#import "SDHSportsNewsModal.h"

@interface SDHSportsHomeNewsCell ()

@property (nonatomic, strong) UIImageView *logoImgView;
@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UILabel *descLb;
@property (nonatomic, strong) UILabel *timeLb;

@end

@implementation SDHSportsHomeNewsCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        UIImageView *imgView = [UIImageView new];
        imgView.clipsToBounds = YES;
        imgView.layer.cornerRadius = 5;
        [self.contentView addSubview:imgView];
        self.logoImgView = imgView;
        
        UILabel *label = [UILabel new];
        label.textAlignment = NSTextAlignmentLeft;
        label.textColor = [UIColor blackColor];
//        label.backgroundColor = [UIColor systemPinkColor];
        label.numberOfLines = 1;
        label.font = [UIFont boldSystemFontOfSize:15];
        [self.contentView addSubview:label];
        self.titleLb = label;
        self.titleLb.hidden = YES;
        
        label = [UILabel new];
        label.textAlignment = NSTextAlignmentLeft;
        label.textColor = [UIColor blackColor];
//        label.backgroundColor = [UIColor greenColor];
        label.numberOfLines = 3;
        label.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:label];
        self.descLb = label;
        
        label = [UILabel new];
        label.textAlignment = NSTextAlignmentRight;
        label.textColor = [UIColor grayColor];
//        label.backgroundColor = [UIColor redColor];
        label.numberOfLines = 1;
        label.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:label];
        self.timeLb = label;
        
        __weak typeof(self) weakSelf = self;
        [self.logoImgView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView).offset(10);
            make.top.equalTo(weakSelf.contentView).offset(5);
            make.width.equalTo(@75);
            make.height.equalTo(@52);
        }];
        
        [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.logoImgView);
            make.left.equalTo(weakSelf.logoImgView.mas_right).offset(10);
            make.right.equalTo(weakSelf.contentView).offset(-10);
        }];
        
        [self.descLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.logoImgView).offset(5);
            make.left.equalTo(weakSelf.titleLb);
            make.right.equalTo(weakSelf.titleLb);
        }];
        
        [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(weakSelf.contentView.mas_bottom).offset(-5);
            make.right.equalTo(weakSelf.contentView).offset(-15);
        }];
        
        // for test
        self.logoImgView.image = [UIImage imageNamed:@"touxiang"];
        self.titleLb.text = @"Today's event";
        self.descLb.text = @"new season experts continue to fly with you";
        self.timeLb.text = @"2020-03-23 17:35";
    }
    return self;
}

- (void)updateContent:(id)obj {
    SDHSportsNewsModal *modal = (SDHSportsNewsModal *)obj;
    [self.logoImgView setImageWithURL:[NSURL URLWithString:modal.img] placeholderImage:[UIImage imageNamed:@"touxiang"]];
    self.titleLb.text = modal.en_label;
    self.descLb.text = modal.en_title;
    self.timeLb.text = modal.time;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
